#ifndef fen_h
#define fen_h

#include <stdio.h>


struct position_t;  // forward declaration

/*
 * Setup pos according to the FEN position.
 *
 * Returns zero in case of failure, non zero in case of success.
 */
int decode_fen(const char* fen, struct position_t* pos);

/*
 * Encode pos as a FEN string.
 *
 * The data is placed in buf and is null-terminated.  No more than
 * buflen characters are used. The return value is the number of
 * characters (not including the trailing '\0') which would have been
 * written to the final string if enough space had been available.
 *
 * When buflen is zero buf can be a null pointer and no characters are
 * produced.
 */
int encode_fen(const struct position_t* pos, char* buf, int buflen);

/*
 * Print pos to f in the FEN format.
 *
 * Return 1 in case of success, 0 in case of error.
 */
int print_fen(FILE* f, const struct position_t* pos);


/*
 * Setup pos according to the EPD position.
 *
 * Returns null in case of failure, otherwise returns a pointer to an
 * array of operations. Elements of even index (including the first
 * element) represent opcodes. Odd indices correspond to the unparsed
 * operands (or null, when there are not operands). The array is
 * closed by a null opcode. The array must be released by a sigle call
 * to the function free.
 */
const char** decode_epd(const char* epd, struct position_t* pos);

/*
 * Encode pos as a EPD string.
 *
 * The data is placed in buf and is null-terminated.  No more than
 * buflen characters are used. The return value is the number of
 * characters (not including the trailing '\0') which would have been
 * written to the final string if enough space had been available.
 * The parameter ops must point to an array with the same structure of
 * that returned by decode_epd.
 *
 * When buflen is zero buf can be a null pointer and no characters are
 * produced.
 */
int encode_epd(const struct position_t* pos, char* buf, int buflen, const char** ops);


/*
 * Parse the argmunets of an EPD operation.
 *
 * The arguments are then placed in the returned array of strings.
 * The array is terminated by a null pointer. In case of failure a
 * null pointer is returned.  The array must be released by a sigle
 * call to the function free.
 */
const char** decode_epd_args(const char* args);


/*
 * Print pos to f in the EPD format.
 *
 * ops must have the same structure used by decode_epd.  Returns 1 in
 * case of success, 0 in case of error.
 */
int print_epd(FILE* f, const struct position_t* pos, const char** ops);


#endif  // fen_h
